package com.smh.a08Test2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {

//        客户端:发送一条数据，接收服务端反馈的消息并打印
//        服务器:接收数据并打印，再给客户端反馈消息

        Socket socket = new Socket("127.0.0.1", 10005);
        //发数据
        OutputStream os = socket.getOutputStream();

        byte[] bytes = "asdasd".getBytes();
        os.write(bytes);
        socket.shutdownOutput();//结束输出流,但是不断开链接

        //读数据
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        StringBuilder sb = new StringBuilder();
        int b;
        while ((b = br.read()) != -1) {
            sb.append((char) b);
        }
        System.out.println(sb);


        os.close();
        br.close();
        socket.close();

//        ServerSocket ss = new ServerSocket(10007);
//        Socket accept = ss.accept();
//        InputStream is = accept.getInputStream();
//        BufferedReader br = new BufferedReader(new InputStreamReader(is));
//
//        StringBuilder sb = new StringBuilder();
//        int b;
//        while ((b = br.read()) != -1) {
//            sb.append((char) b);
//        }
//        br.close();
//        ss.close();

    }
}
